package com.yan.supermangesystem.service;

import com.yan.jingdongshop.dao.Dao;
import com.yan.supermangesystem.dao.SuperDao;
import com.yan.supermangesystem.domain.UserInfo;

import java.util.Scanner;
import java.util.Set;

public class SuperServicelmpl implements SuperService {

    public static final Scanner INPUT = new Scanner(System.in);
    @Override
    public void inital() {
        SuperDao.member.put("1001" , new UserInfo("1001", "冯程程", "铂金卡", 2000, "合法账户"));
        SuperDao.member.put("1002" , new UserInfo("1002", "孙悟空", "钻石卡", 5000, "被禁账户"));
        SuperDao.member.put("1003" , new UserInfo("1003", "张巧巧", "金卡  ", 500, "  合法账户"));
    }

    @Override
    public void searchAll() {
        System.out.println("用户ID\t\t账号\t\t卡类型\t\t积分\t\t卡状态");
        Set<String> keySet = SuperDao.member.keySet();
        for (String id : keySet) {
            System.out.println(SuperDao.member.get(id).getId() + "\t\t" + SuperDao.member.get(id).getAccount() + "\t\t" + SuperDao.member.get(id).getCardType() + "\t\t" + SuperDao.member.get(id).getPoints() + "\t\t" + SuperDao.member.get(id).getStatue());
        }
    }

    @Override
    public void deleteUserInfo() {
        System.out.println("请输入要删除的会员ID号:");
        String Uid = INPUT.next();
        Set<String> keySet = SuperDao.member.keySet();
        for (String id : keySet) {
            if(Uid.equals(id)){
                    System.out.println("您确定要删除吗(y/n)");
                    String choice = INPUT.next();
                    if("y".equals(choice)){
                        SuperDao.member.remove(id);
                        System.out.println("删除成功");
                        return;
                    }
            }
        }
        System.out.println("对比起，您要删除的会员ID不存在,请核实后再删除！");
        /*for (UserInfo userInfo : SuperDao.hashSet) {
            if(userInfo.getId().equals(Uid)){
                System.out.println("您确定要删除吗(y/n)");
                String choice = INPUT.next();
                if("y".equals(choice)){
                    SuperDao.hashSet.remove(userInfo);
                }else {
                    break;
                }
            }else {
                System.out.println("对比起，您要删除的会员ID不存在,请核实后再删除！");
            }
        }*/

    }

    @Override
    public void addUserInfo() {
        System.out.println("请输入用户ID");
        String sid = INPUT.next();
        System.out.println("请输入账号");
        String account = INPUT.next();
        System.out.println("请输入卡类型");
        String type = INPUT.next();
        System.out.println("请输入积分");
        int point = INPUT.nextInt();
        System.out.println("请输入卡状态");
        String status = INPUT.next();

        UserInfo use = new UserInfo(sid , account , type , point , status);
        SuperDao.member.put(sid , use);
    }
}
